cmake_minimum_required(VERSION 3.16)

project(plugin_output LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#设置输出目录为 ../../output（相对于构建目录）
# set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/../output/")
# set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/../../output/")
file(MAKE_DIRECTORY ${OUTPUT_DIR})  # 确保目录存在
message(STATUS "Final output path: ${OUTPUT_DIR}")

# 明确查找 Core + Widgets 模块
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets SerialPort Network SerialBus)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets SerialPort Network SerialBus)

add_library(plugin_output SHARED
  plugin_output.cpp
  plugin_output.h
  plugin_output.json
  ../../IPlugin.h
  plugin_output.ui
  outputconfigwidget.h outputconfigwidget.cpp outputconfigwidget.ui
  remotetab.h remotetab.cpp remotetab.ui
  modbusslave.h modbusslave.cpp
  ../../../maxtool/DateTimeButton/DateTimeButton.h
  ../../../maxtool/DateTimeButton/DateTimeButton.cpp
  ../../../maxtool/LineEdit/customlineedit.h
  ../../../maxtool/LineEdit/customlineedit.cpp
)

# 设置动态库输出路径（兼容Windows/Linux）
set_target_properties(plugin_output PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # Linux的.so文件路径
  RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # Windows的.dll文件路径
  ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # 静态库（可选）
)

# 添加头文件搜索路径
target_include_directories(plugin_output PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/../..  # 确保能找到 ../../IPlugin.h
  ${CMAKE_CURRENT_SOURCE_DIR}/../../../maxtool
)

# 链接 Qt Widgets 模块
target_link_libraries(plugin_output PRIVATE
  Qt${QT_VERSION_MAJOR}::Core
  Qt${QT_VERSION_MAJOR}::Widgets
  Qt${QT_VERSION_MAJOR}::SerialPort
  Qt${QT_VERSION_MAJOR}::SerialBus
  Qt${QT_VERSION_MAJOR}::Network
)
